import Vue from 'vue'
import VueRouter from 'vue-router'
import Home from '../views/Home.vue'

Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    name: 'Home',
    component: Home
  },
  {
    path: '/about',
    name: 'About',
    component: () => import( '../views/About.vue')
  },
  {
    path: '/user',
    name: 'user',
    component: () => import( '../views/user.vue'),
      // 路由独享守卫
    // beforeEnter:(to,from,next)=>{
    //   // 判断用户时候登录没有登录不让进
    //   alert("当前是vip页面您没有登录你能进入"+to+from);
    //   next("/denglu")
    // }
  },
  {
    path: '/denglu',
    name: 'denglu',
    component: () => import( '../views/denglu.vue')
  },
  {
    path: '/zhuce',
    name: 'zhuce',
    component: () => import( '../views/zhuce.vue'),
  
  },
]

const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
})

// 全局前置守卫
// router.beforeEach((to,from,next)=>{
//   if(to.path=="/zhuce"||to.path=="/denglu"){
//     next()
//   }else{
//     alert("您没有登录请您登录后访问");
//     next(false)
//   }


//   console.log(to);
//   console.log(from);
 
// })

// 全局后置守卫
// router.afterEach((to,from)=>{
//   console.log("进入啦" +to+from);
// })

export default router
